const Methods = ["push", "pop", "unshift", "shift", "splice"];
const oldArrayProtoMethods = Array.prototype;

const ArrayMethods = Object.create(oldArrayProtoMethods);

Methods.forEach((item) => {
    ArrayMethods[item] = function (...args) {
        let result = oldArrayProtoMethods[item].apply(this, args);
        let inserted;
        switch (item) {
            case "push":
            case "unshift":
                inserted = args;
                break;
            case "splice":
                inserted = args.splice(2);
                break;

            default:
                break;
        }

        const ob = this.__ob__
        if (inserted) {
            ob.observerArray(inserted)
        }
        ob.dep.notify()
        return result;
    };
});

export { ArrayMethods };
